<template>
<h1>循环指令</h1>
  <ul>
<!--    item从1开始，每执行一次，item的值就+1，一直到数字n -->
<!--    v-for的效果：每执行5次，生成5个li，里面的数字是1~5 -->
    <li v-for="p in productArr">{{p}}</li>
  </ul>
  <table border="1" align="center">
    <tr>
      <th>商品序号</th>
      <th>商品名称</th>
      <th>商品价格</th>
      <th>商品库存</th>
      <th>商品操作</th>
    </tr>
    <tr v-for="(item,index) in productArr">
      <td>{{index+1}}</td>
      <td>{{item.title}}</td>
      <td>{{item.price}}</td>
      <td>{{item.num}}</td>
      <td><button @click="del(index)">删除</button></td>
    </tr>
  </table>
</template>
<script setup>
import {ref} from "vue";
import index from "vuex";

const productArr=ref([
  {title:'苹果', price:50,num:100},
  {title:'香蕉', price:100,num:100},
  {title:'葡萄', price:200,num:20},
  {title:'桃子', price:25,num:50},
  {title:'桃子', price:25,num:50},
  {title:'桃子', price:25,num:50},
  {title:'桃子', price:25,num:50},
  {title:'桃子', price:25,num:50},
  {title:'桃子', price:25,num:50},
  {title:'桃子', price:25,num:50},
  {title:'桃子', price:25,num:50},
  {title:'桃子', price:25,num:50},
  {title:'桃子', price:25,num:50}
]);
const del=(index)=>{
  if (confirm('您确定删除吗？')){
    productArr.value.splice(index,1);
  }
}
</script>


<style scoped>

</style>